import { createRouter, createWebHashHistory } from "vue-router";
/* import Home from "../views/Home.vue"; */
//路由表
const routes = [
  {
    //重定向
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    redirect: "/home/homepage",
  },
  {
    //首页
    path: "/home/homepage",
    component: () => import("../components/home/homepage/Page"),
  },
  {
    //课程页面
    path: "/home/curriculum",
    component: () => import("../components/home/curriculum/Curriculum"),
  },
  {
    //训练营
    path: "/home/my/Camp",
    component: () => import("../components/home/MypageJump/Camp"),
  },
  {
    //开课页面
    path: "/home/my/Details",
    component: () => import("../components/home/MypageJump/Details"),
  },
  {
    //成长页面
    path: "/home/growup",
    component: () => import("../components/home/growup/Growup"),
  },
  {
    //我的页面
    path: "/home/my",
    component: () => import("../components/home/my/My"),
  },
  {
    //钻石兑换页面
    path: "/home/my/MypageJump",
    component: () => import("../components/home/MypageJump/ShoppingMall"),
  },
  {
    //邀请有礼页面
    path: "/home/my/Extension",
    component: () => import("../components/home/MypageJump/Extension"),
  },
  {
    //公众号页面
    path: "/home/my/Officalaccount",
    component: () => import("../components/home/MypageJump/Officalaccount"),
  },
  {
    //检测页面
    path: "/home/my/Testing",
    component: () => import("../components/home/MypageJump/Testing"),
  },
  {
    //设置页面
    path: "/home/my/Setup",
    component: () => import("../components/home/MypageJump/Setup"),
  },
  {
    //登陆注册页面
    path: "/home/my/Login",
    component: () => import("../components/home/MypageJump/Login"),
  },
  {
    //个人信息页面
    path: "/home/my/Personal",
    component: () => import("../components/home/MypageJump/Personal"),
  },

  //404页面
  {
    path: "/:pathMatch(.*)*",
    component: () => import("../views/NotFound"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 需要登录
  if (to.meta.requireLogin) {
    if (localStorage.getItem("token")) {
      next();
    } else {
      next("/login");
    }
  } else {
    next();
  }
});
export default router;
